﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PharmacyBussinesEntities;

namespace PharmacyRepositoy.Mapping
{
    public class DetalleVentaMap:EntityTypeConfiguration<DetalleVenta>
    { public DetalleVentaMap()
        {
            this.HasKey(p => new { p.Item, p.IdVenta });

            this.Property(p => p.Item)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(p => p.Cantidad)
                .HasPrecision(9, 2)
                .IsRequired();

            this.Property(p => p.PrecioUnit)
                .HasPrecision(9, 2)
                .IsRequired();

            this.Ignore(p => p.Monto);

            this.ToTable("DETALLEVENTA");

            this.Property(p => p.Item).HasColumnName("Item");
            this.Property(p => p.Cantidad).HasColumnName("Cantidad");
            this.Property(p => p.PrecioUnit).HasColumnName("PrecioUnit");

            this.HasRequired(p => p.Lote)
                .WithMany()
                .HasForeignKey(p => p.IdVenta)
                .WillCascadeOnDelete(false);

            this.HasRequired(d => d.Venta)
                .WithMany(v => v.DetalleVenta)
                .HasForeignKey(d => d.IdVenta)
                .WillCascadeOnDelete(false);
        }
    }

    }
